#ifndef PROJECTZ_NUSER_NCOMMAND_CS_REQ_RANDOM_STAT_H_
#define PROJECTZ_NUSER_NCOMMAND_CS_REQ_RANDOM_STAT_H_

#include "../../engine.h"

#include "../../User.h"

namespace ProjectZ { namespace NCommand { namespace NWorld {

class CS_REQ_RANDOM_STAT
{
public:
	static void OnExecute(User * pUser, ::Network::Packet * pPacket)
	{
		// MAX 를 넘은 경우 ZEN 을 확인하여 ZEN 차감 하여 처리한다...

		/*
		 * //랜덤 스탯 요청
		CS_REQ_RANDOM_STAT					0x0938
		{
			u8 slot_idx;
			u8 u8class_type;				/// 클래스 타입
		}

		SC_REQ_RANDOM_STAT					0x0939
		{
			s16	ack;						/// 1:완료 ,  -1 실패

			u8 left_stat_reset_count;		/// 무료 스탯재설정 남은 횟수 (없으면 0)

			u8 stat_str;
			u8 stat_dex;
			u8 stat_con;
			u8 stat_spi;
		}

		 */



		STRESSLOG("[CHANNEL] CS_REQ_RANDOM_STAT::ONEXECUTE");

		PREPARE_PACKET;

		uint8_t slot_number = 0;
		uint8_t class_type = 0;

		* pPacket >> slot_number >> class_type;

		if (0 > slot_number || slot_number > 8)
		{
			Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
			* pAck << static_cast<uint16_t>(-1);
			* pAck << static_cast<uint8_t>(0);
			* pAck << static_cast<uint8_t>(0);
			* pAck << static_cast<uint8_t>(0);
			* pAck << static_cast<uint8_t>(0);
			* pAck << static_cast<uint8_t>(0);
			pAck->MakePacket(CMD_SC_REQ_RANDOM_STAT);
			pUser->Send(pAck);

			return;
		}

		if (0 < pUser->GetUserInfo().array_Slot[slot_number].remainStatResetCount)
		{
			int str = 0;
			int con = 0;
			int dex = 0;
			int spi = 0;

			str = rand() % (STAT_MAX-STAT_MIN+1) + STAT_MIN;
			dex = rand() % (STAT_MAX-STAT_MIN+1) + STAT_MIN;
			spi = rand() % (STAT_MAX-STAT_MIN+1) + STAT_MIN;
			con = STAT_SUM_MAX - (str + dex + spi);

			pUser->GetCharacterInfoFromIndex(slot_number).str = str;
			pUser->GetCharacterInfoFromIndex(slot_number).dex = dex;
			pUser->GetCharacterInfoFromIndex(slot_number).spi = spi;
			pUser->GetCharacterInfoFromIndex(slot_number).con = con;

			pUser->GetUserInfo().array_Slot[slot_number].remainStatResetCount--;

			Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
			* pAck << static_cast<uint16_t>(1);
			* pAck << static_cast<uint8_t>(pUser->GetUserInfo().array_Slot[slot_number].remainStatResetCount);
			* pAck << static_cast<uint8_t>(str);
			* pAck << static_cast<uint8_t>(dex);
			* pAck << static_cast<uint8_t>(spi);
			* pAck << static_cast<uint8_t>(con);
			pAck->MakePacket(CMD_SC_REQ_RANDOM_STAT);
			pUser->Send(pAck);

			return;
		}
		else
		{
			Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
			* pAck << static_cast<uint16_t>(-1);
			* pAck << static_cast<uint8_t>(0);
			* pAck << static_cast<uint8_t>(0);
			* pAck << static_cast<uint8_t>(0);
			* pAck << static_cast<uint8_t>(0);
			* pAck << static_cast<uint8_t>(0);
			pAck->MakePacket(CMD_SC_REQ_RANDOM_STAT);
			pUser->Send(pAck);
		}
	}
};

} /*NWorld*/ } /*NCommand*/ } /*ProjectZ*/


#endif /* PROJECTZ_NUSER_NCOMMAND_CS_REQ_RANDOM_STAT_H_ */
